package com.cn.action;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.cn.dao.DoctorDao;
import com.cn.dao.UserDao;

import com.cn.entity.Doctor;
import com.cn.entity.User;
import com.opensymphony.xwork2.Action;

public class LoginAction implements Action{

    String username;
    String password;
    String radio;
;
	 

		public String getUsername() {
		return username;
	}


	public void setUsername(String username) {
		this.username = username;
	}


	public String getPassword() {
		return password;
	}


	public void setPassword(String password) {
		this.password = password;
	}


	
	


		public String getRadio() {
		return radio;
	}


	public void setRadio(String radio) {
		this.radio = radio;
	}


		@Override
		public String execute() throws Exception {
			// TODO Auto-generated method stub
		System.out.println(radio);
		String sql="login";	
		HttpSession session=ServletActionContext.getRequest().getSession();	
		if (radio.equals("1")){ User u=new User(username,password);
			
			UserDao ud=new UserDao();
			User user=ud.login(u);
			if (user!=null){   session.setAttribute("user",user); sql="user";                }
			
		}	
		
		
		
		else{     Doctor doc=new Doctor(username, password);     DoctorDao dd=new DoctorDao();
		
        doc=dd.login(doc);
		
		if(doc!=null) {
			
			           
		
		
		
		
		if (doc.getPro()==2){sql="keshi";  session.setAttribute("doctor", doc);                 }
		
		if (doc.getPro()==3){sql="tijian";   session.setAttribute("doctor", doc);                }
		
		if (doc.getPro()==8){sql="success";    session.setAttribute("manager", doc);               }
		
		
		}
		
		
		
		
           	}                                                            
			
    	
    	
		return sql;
	}


}